import  { AppPostT } from '@/utils/request'
import { BasicPageSearch, ActionResult } from '@/models/basicType'
import {
    MyMaterialOverview, MyMaterialPageResult, MaterialPageSearch, MaterialPageResult, RecMaterialPageResult, RecMaterialPageSearch,
    DocPkgPageSearch, DocPkgPageResult, DocPkgMaterialPageSearch, DocPkgMaterialPageResult
} from '@/models/material'

// 获取我的资料概览
export async function getMyOverview() {
    const data = {}
    const res = await AppPostT<MyMaterialOverview>("/doc/overview",data)
    console.log("getMyOverview request:", data, ", result:", res)
    return res.data ? res.data : {} as MyMaterialOverview
}

// 获取我的资料列表
export async function getMyMaterials(data: BasicPageSearch) {
    const res = await AppPostT<MyMaterialPageResult>("/doc/myList",data)
    console.log("getMyMaterials request:", data, ", result:", res)
    return res.data ? res.data : {} as MyMaterialPageResult
}

// 加为我的资料
export async function addAsMyMaterial(id:number) {    
    const data = {id};
    const res = await AppPostT<ActionResult>("/doc/add",data)
    console.log("addAsMyMaterial request:", data, ", result:", res)
    return res.data ? res.data : {} as ActionResult
}

// 删除我的资料列表
export async function deleteMyMaterials(ids:number[]) {    
    const data = {ids};
    const res = await AppPostT<ActionResult>("/doc/del",data)
    console.log("deleteMyMaterials request:", data, ", result:", res)
    return res.data ? res.data : {} as ActionResult
}

// 获取资料列表（专题页/精选）
export async function getRecMaterials(data: RecMaterialPageSearch) {
    const res = await AppPostT<RecMaterialPageResult>("/doc/rec/list",data)
    console.log("getRecMaterials request:", data, ", result:", res)
    return res.data ? res.data : {} as RecMaterialPageResult
}

// 获取全部资料列表（分页）
export async function getAllMaterials(data: MaterialPageSearch) {
    const res = await AppPostT<MaterialPageResult>("/doc/list",data)
    console.log("getAllMaterials request:", data, ", result:", res)
    return res.data ? res.data : {} as MaterialPageResult
}

// 获取资料包推荐列表（分页）
export async function getRecDocPkgs(data: DocPkgPageSearch) {
    const res = await AppPostT<DocPkgPageResult>("/docpkg/rec/list",data)
    console.log("getRecDocPkgs request:", data, ", result:", res)
    return res.data ? res.data : {} as DocPkgPageResult
}

// 获取指定资料包资料列表（分页）
export async function getDocPkgMaterials(data: DocPkgMaterialPageSearch) {
    const res = await AppPostT<DocPkgMaterialPageResult>("/docpkg/doc/list",data)
    console.log("getDocPkgMaterials request:", data, ", result:", res)
    return res.data ? res.data : {} as DocPkgMaterialPageResult
}
